﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SWDataDB.Models;
using SWDataDB.BLL;
using SWDataDB.DAL;
using System.Data;

public partial class AdminManage_Edit_PMEdit : System.Web.UI.Page
{

    public string pmid = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        pmid = Request["pmid"];
        bind();
    }


    private void bind()
    {
        PMInfo pmquery = new PMInfo();
        int PMID = Convert.ToInt32(pmid);
        DataSet ds = pmquery.SelectInfoByID(PMID);
        DataRowView dv = ds.Tables[0].DefaultView[0];

        
        
      
        ZL_FILE_ID.Text = Convert.ToString(dv.Row["ZL_FILE_ID"]);
 

        PM_NAME.Text = Convert.ToString(dv.Row["PM_NAME"]);
        PM_CODE.Text = Convert.ToString(dv.Row["PM_CODE"]);
        BB_NUM.Text = Convert.ToString(dv.Row["BB_NUM"]);
        YP_NUM.Text = Convert.ToString(dv.Row["YP_NUM"]);



        GP_NUM.Text = Convert.ToString(dv.Row["GP_NUM"]);
        BOP_NUM.Text = Convert.ToString(dv.Row["BOP_NUM"]);
        PM_QUALITY.InnerText = Convert.ToString(dv.Row["PM_QUALITY"]);//行政区划
        SCALE.Text = Convert.ToString(dv.Row["SCALE"]);

        PM_SLON_D.Text = Convert.ToString(dv.Row["PM_SLON"]).Substring(0, 3);

        PM_SLON_F.Text = Convert.ToString(dv.Row["PM_SLON"]).Substring(3, 2);
        PM_SLON_M.Text = Convert.ToString(dv.Row["PM_SLON"]).Substring(5);

        PM_SLAT_D.Text = Convert.ToString(dv.Row["PM_SLAT"]).Substring(0, 2);
        PM_SLAT_F.Text = Convert.ToString(dv.Row["PM_SLAT"]).Substring(2, 2);

        PM_SLAT_M.Text = Convert.ToString(dv.Row["PM_SLAT"]).Substring(4);



        PM_SUMMARY.InnerText = Convert.ToString(dv.Row["PM_SUMMARY"]);
        PM_LDES.InnerText = Convert.ToString(dv.Row["PM_LDES"]);
        PM_IMAGE.Text = Convert.ToString(dv.Row["PM_IMAGE"]);
        KEY_WORDS.Text = Convert.ToString(dv.Row["KEY_WORDS"]);
        TEST_PEOPLE.Text = Convert.ToString(dv.Row["TEST_PEOPLE"]);
        PM_DATE.Text = Convert.ToString(dv.Row["PM_DATE"]);


        //从著录表中读取title
        ZLInfo ZLFILEID = new ZLInfo();
        ZL_TBL zl = ZLFILEID.SelectZLInfoByID(dv.Row["ZL_FILE_ID"].ToString());
        TITLE_.Text = zl.O_TITLE;
        FileTitle.Text = zl.O_TITLE;


    }


    protected void submit_Click(object sender, EventArgs e)
    {
        PM_TBL pm_info = new PM_TBL();
        PMInfo kc_in = new PMInfo();

        pm_info.O_ZL_FILE_ID = Request.Form["ZL_FILE_ID"];
        pm_info.O_PM_NAME = Request.Form["PM_NAME"];
        pm_info.O_PM_CODE = Request.Form["PM_CODE"];


        pm_info.O_BB_NUM = int.Parse((Request.Form["BB_NUM"]));
        pm_info.O_YP_NUM = int.Parse((Request.Form["YP_NUM"]));
        pm_info.O_GP_NUM = int.Parse((Request.Form["GP_NUM"]));
        pm_info.O_BOP_NUM = int.Parse((Request.Form["BOP_NUM"]));


        pm_info.O_PM_SLON = int.Parse((Request.Form["PM_SLON_D"] + Request.Form["PM_SLON_F"] + Request.Form["PM_SLON_M"]));
        pm_info.O_PM_SLAT = int.Parse((Request.Form["PM_SLAT_D"] + Request.Form["PM_SLAT_F"] + Request.Form["PM_SLAT_M"]));


        pm_info.O_PM_QUALITY = this.PM_QUALITY.InnerText;
        pm_info.O_PM_SUMMARY = this.PM_SUMMARY.InnerText;
        pm_info.O_SCALE = Request.Form["SCALE"];

        pm_info.O_PM_LDES = this.PM_LDES.InnerText;

        pm_info.O_KEY_WORDS = Request.Form["KEY_WORDS"];

        pm_info.O_TEST_PEOPLE = Request.Form["TEST_PEOPLE"];
        pm_info.O_PM_DATE = Request.Form["PM_DATE"];

        pm_info.O_ID =int.Parse(pmid) ;

        if (kc_in.UpdatePMInfo(pm_info) == 1)
        {
            bind();
            Response.Write("<script language=javascript>alert('更新成功！');location='../Manage/PMManage.aspx'</script>");
            //Response.Redirect("ZLManage.aspx");
        }
        else
        {
            Response.Write("<script language=javascript>alert('更新失败！');location='../Manage/PMManage.aspx'</script>");
        }
    }
}